<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"
	import="java.util.*,com.telecom.cms.dao.*,com.telecom.cms.dto.*,java.sql.*"%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Insert title here</title>
		<STYLE type=text/css>
BODY {
	SCROLLBAR-FACE-COLOR: #f2f2f2;
	SCROLLBAR-HIGHLIGHT-COLOR: #f2f2f2;
	SCROLLBAR-SHADOW-COLOR: #b7b7b7;
	SCROLLBAR-3DLIGHT-COLOR: #f2f2f2;
	SCROLLBAR-ARROW-COLOR: #999999;
	SCROLLBAR-TRACK-COLOR: #e9e9e9;
	SCROLLBAR-DARKSHADOW-COLOR: #f2f2f2;
	SCROLLBAR-BASE-COLOR: #f2f2f2
}
</STYLE>
		<link rel="stylesheet" type="text/css" href="images/main.css">
		<script type="text/javascript" src="dtree.js"></script>
		<script>
window.parent.outer_frame.rows="98%,15,*";
window.parent.ctlFrame.frameshow.src="images/pull_down.jpg";
 
function checkAll(str) 
{ 
  var a = document.getElementsByName(str); 
  var n = a.length; 
  for (var i=0; i<n; i++) 
     a[i].checked = window.event.srcElement.checked; 
} 

function checkItemMul(str) 
{ 
    var e = window.event.srcElement; 
    var all = eval("document.form1."+ str); 
    var i=0,j=0;
    for(i=0;i<all.length;i++)
      if(all[i].value==e.name)
        j=i;
        
    var a = document.getElementsByName(e.name); 
    if (all.length>1)
       all[j].checked = false; 
    else
       all.checked = false;
    for (i=0; i<a.length; i++) 
    { 
       if (a[i].checked)
       { 
         if (all.length>1)
            all[j].checked = true; 
         else
            all.checked = true;
         break;
       } 
    } 
}

function chacksel(){

  var r = document.form1.type ;
  
  var   j=0;   
  for(i=0;i<r.length;i++){  
       if(r[i].checked)
           j++;   
       }  
        if(j<1){   
          alert("请定制用户分群的结果字段!!");   
          return   false;   
        } 
  return true ; 

}

function querymodel(){
		document.form1.action="atomGet4RSModelDEF.do"
		document.getElementById("operation").value="list";
		document.form1.target="upFrame";
		document.form1.submit();
	}
		

</script>
	</head>
	<body>
		<form name="form1" method="post" target="rsFrame" action="output.do"
			onSubmit="return chacksel()">

			<table width="700" cellspacing="0" cellpadding="0" border="0">
				<tbody>
					<tr>
						<td width="3" height="31">
							<img height="31" src="images/table_01.gif" width="3" />
						</td>
						<td background="images/table_02.gif" colspan="2" height="31">
							<table cellspacing="0" cellpadding="0" width="146" align="left"
								border="0">
								<tbody>
									<tr>
										<td width="51" background="images/title_1_bg.gif">
											<img height="31" src="images/title_1.gif" width="51" />
										</td>
										<td width="95" background="images/title_1_bg.gif">
											<span class="color_b_666">结果展示定制</span>
										</td>
									</tr>
								</tbody>
							</table>
							<center>
								<table align="right">
									<tr align="right">
										<td>
											<input id="copycondition" type="checkbox"
												name="copycondition" value="yes"
												<%
												String copycondition=request.getParameter("copycondition");
															if(copycondition==null){
																copycondition=(String)request.getAttribute("copycondition");
															}
												if("yes".equals(copycondition)){out.print("checked");} %>
												onclick="querymodel()">
											复制条件&nbsp 选择模板:
											<select id="templateId" name="templateId"
												onchange="querymodel()">
												<option value="0">
													清空
												</option>
												<%
													Connection con = GetConnect.getCsConnection();
													String oldid = (String) session.getAttribute("oldid");
													SEG_SUBJECT_TEMPLATE_DEFDAO templatedao = new SEG_SUBJECT_TEMPLATE_DEFDAO(
															con);
													List templist = templatedao.findAll("1", "admin");
													Iterator it = templist.iterator();
													while (it.hasNext()) {
														SEG_SUBJECT_TEMPLATE_DEFDTO templatedto = (SEG_SUBJECT_TEMPLATE_DEFDTO) (it
																.next());
														String templatename = templatedto.getTemplateName();
														String templateid = templatedto.getTemplateId().toString();
												%>
												<option value="<%=templateid%>"
													<%if(templateid.equals(request.getParameter("templateId"))){
													 	out.print(" selected");
													}else if(templateid.equals(session.getAttribute("selectedtemplate"))){
														out.print(" selected"); 
													}
													 
													 %>>
													<%=templatename%>
												</option>
												<%
													}
												%>
											</select>
										</td>
										<td valign="bottom" align="right">
											<input type="submit" name="Submit" value="提交所选结果字段">
										</td>
									</tr>
								</table>
							</center>
						</td>
						<td width="3">
							<img height="31" src="images/table_03.gif" width="3" />
						</td>
					</tr>
					<tr>
						<td height="172">
							<img height="100%" src="images/table_04.gif" width="3" />
						</td>
						<td style="PADDING-TOP: 3px" valign="top" colspan="2">

							<table width="700" height="129" border="0" align="left"
								cellpadding="1" cellspacing="1" class="moduleList">
								<tr>
									<%
										List conditionAtoms = (List) session.getAttribute("AtomList");
										SEG_BIZ_GROUP_DEFDAO dao = new SEG_BIZ_GROUP_DEFDAO(con);
										List grouplist = dao.findAll();
										int j = 0;
										for (int i = 0; i < grouplist.size(); i++) {

											SEG_BIZ_GROUP_DEFDTO groupdto = (SEG_BIZ_GROUP_DEFDTO) grouplist
													.get(i);

											if (groupdto.getATOM_GROUP_ID() == 400006) {
												continue;
											}
											SEG_ATOM_GROUP_RELDAO reldao = new SEG_ATOM_GROUP_RELDAO(con);

											List rellist = reldao.findById(groupdto.getATOM_GROUP_ID());

											List atomlist = new ArrayList();

											if (j % 3 == 0 && j != 0) {
									%>

								</tr>
								<tr>

									<%
										}
									%>

									<td width="232" align="left">
										<TABLE width="100%" height="26" border=0 cellPadding=1
											cellSpacing=1 id=table18 bgcolor=#d5d5d5>
											<TR bgColor=#d5d5d5 height="26">
												<TD width="230" vAlign=top background="images/atom_02.gif">
													<SPAN class=en_big><input type="checkbox" id="type"
															name="type" value="<%=groupdto.getATOM_GROUP_NAME()%>"
															onclick="checkAll('<%=groupdto.getATOM_GROUP_NAME()%>')">

														<%=groupdto.getATOM_GROUP_NAME()%></SPAN>
												</TD>
											</TR>
											<TR bgcolor="#FFFFFF">
												<td height="100" align=left>
													<div style="height: 100px; width: 230px; overflow-y: auto;">
														<%
																					for (int k = 0; k < rellist.size(); k++) {
																					SEG_ATOM_GROUP_RELDTO seg_ATOM_GROUP_RELDTO = (SEG_ATOM_GROUP_RELDTO) rellist
																					.get(k);
																					SEG_BIZ_ATOM_DEFDAO atomdao = new SEG_BIZ_ATOM_DEFDAO(
																					con);
																					SEG_BIZ_ATOM_DEFDTO atomdto = atomdao
																					.findById(seg_ATOM_GROUP_RELDTO.getBIZ_ATOM_ID());
																					if (atomdto.getVALUE_TYPE_ID() != 1000
																					&& atomdto.getVALUE_TYPE_ID() != 2000) {
																						atomlist.add(atomdto);
																					}
																						}
																						if (atomlist.size() > 0)
																					for (int m = 0; m < atomlist.size(); m++) {
																						SEG_BIZ_ATOM_DEFDTO showdto = (SEG_BIZ_ATOM_DEFDTO) atomlist
																						.get(m);
														%>
														<input type="checkbox"
															name=<%=groupdto.getATOM_GROUP_NAME()%>
															value="<%=showdto.getBIZ_ATOM_ID()%>"
															<%
															boolean conditionchecked=false;
															List modelDisplay=(List)request.getAttribute("modelDisplay");
															if(modelDisplay!=null){
																Iterator iter=modelDisplay.iterator();
																while(iter.hasNext()){
																int display = ((SEG_TEMPLATE_ATOM_DEFDTO)iter.next()).getBizAtomId();
																int show = showdto.getBIZ_ATOM_ID();
																	if(show==display)
																	{
																		out.print("checked ");
																		conditionchecked=true;
																	} 
																}
															}
															if(conditionAtoms!=null&&"yes".equals(copycondition)){
																Iterator iterator=conditionAtoms.iterator();
																while(iterator.hasNext()){
																	String tiaojian = ((ShowatomDTO)iterator.next()).getAtomname();
																	String jieguo = showdto.getBIZ_ATOM_NAME();
																	if(jieguo.indexOf(tiaojian)!=-1)
																	{
																		out.print("checked ");
																		conditionchecked=true;
																	} 
																}
															}
															List outputlist=(List)session.getAttribute("Outputlist");
															if(outputlist!=null){
																Iterator iter=outputlist.iterator();
																while(iter.hasNext()){
																int display = ((SEG_BIZ_ATOM_DEFDTO)iter.next()).getBIZ_ATOM_ID();
																int show = showdto.getBIZ_ATOM_ID();
																	if(show==display)
																	{
																		out.print("checked ");
																		conditionchecked=true;
																	} 
																}
															}
															
															%>
															onclick="checkItemMul('type')">
														<%
															if (conditionchecked) {
														%>
														<script type="text/javascript">
															all = document.getElementsByName('type');
															    for(i=0;i<all.length;i++)
      															if(all[i].value=='<%=groupdto.getATOM_GROUP_NAME()%>')
        														{
        															all[i].checked=true;
        														}
														</script>
														<%
															}
														%>
														<%=showdto.getBIZ_ATOM_NAME().trim()%>
														<br>
														<%
															}//end of form
														%>
													</div>
												</td>
											</TR>

										</TABLE>
									</td>
									<%
										j++;
										}
									%>
								</tr>
								<tr>
									<td colspan="4">
										<center>
											<input type="submit" name="Submit" value="提交所选结果字段">
										</center>
									</td>
								</tr>
							</table>
						<td background="images/table_05.gif">
							<img height="53" src="images/table_05.gif" width="3">
						</td>
					</tr>
					<tr>
						<td>
							<img height="12" src="images/table_06.gif" width="3">
						</td>
						<td>
							<img height="3" src="images/table_07.gif" width="100%">
						</td>
						<td>
							<img height="12" src="images/table_08.gif" width="3">
						</td>
					</tr>
				</tbody>
			</table>
			<input type="hidden" id="operation" name="method" value="">
		</form>

	</body>
</html>
